﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using wms_wpf.Apiservice;
using wms_wpf.Dto;
using wms_wpf.InPut;

namespace wms_wpf.ViewModels
{
    public class MergeViewModel : BindableBase, INavigationAware
    {

        public MergeViewModel() 
        {
            View_Box_MaterialDtos = new List<View_Box_MaterialDto>();
            View_Box_MaterialDto2s = new List<View_Box_MaterialDto>();
            viewService =new ViewService();
            baseService=new BaseService();
            GetList_View_Box_MaterialCommand = new DelegateCommand(GetList_View_Box_Material);
            GetList_View_Box_MaterialCommand2 = new DelegateCommand(GetList_View_Box_Material2);
            MergeCommand=new DelegateCommand(Merge);

        }

        private readonly IViewService viewService;
        private readonly IBaseService baseService;
        public DelegateCommand GetList_View_Box_MaterialCommand { get; set; }
        public DelegateCommand GetList_View_Box_MaterialCommand2 { get; set; }
        public DelegateCommand MergeCommand { get; set; }

        private List<View_Box_MaterialDto> view_Box_MaterialDtos;
        public List<View_Box_MaterialDto> View_Box_MaterialDtos
        {
            get { return view_Box_MaterialDtos; }
            set { view_Box_MaterialDtos = value;RaisePropertyChanged();}
        }
        private List<View_Box_MaterialDto> view_Box_MaterialDto2s;
        public List<View_Box_MaterialDto> View_Box_MaterialDto2s
        {
            get { return view_Box_MaterialDto2s; }
            set { view_Box_MaterialDto2s = value; RaisePropertyChanged(); }
        }


        private string boxcode;
        public string BoxCode
        {
            get { return boxcode; }
            set { boxcode = value;RaisePropertyChanged(); }
        }
        private string boxcode2;
        public string BoxCode2
        {
            get { return boxcode2; }
            set { boxcode2 = value; RaisePropertyChanged(); }
        }
        private string lpn;
        public string LPN
        {
            get { return lpn; }
            set { lpn = value;RaisePropertyChanged(); }
        }
        private string boxgrid;
        public string BoxGrid
        {
            get { return boxgrid; }
            set { boxgrid = value;RaisePropertyChanged(); }
        }


        public async void GetList_View_Box_Material()
        {
            try
            {
                if (string.IsNullOrEmpty(BoxCode)) return;
                View_Box_MaterialDtos = await viewService.GetList_View_Box_Material(BoxCode);
            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                LognetHelper.WriteLog("系统-GetList_View_Box_Material", ex);
            }

        }
        public async void GetList_View_Box_Material2()
        {
            try
            {
                if (string.IsNullOrEmpty(BoxCode2)) return;
                View_Box_MaterialDto2s = await viewService.GetList_View_Box_Material(BoxCode2.Substring(0,10));
            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                LognetHelper.WriteLog("系统-GetList_View_Box_Material2", ex);
            }
       
        }
        public async void Merge()
        {
            try
            {
                if (string.IsNullOrEmpty(BoxCode2) || string.IsNullOrEmpty(BoxCode) || string.IsNullOrEmpty(LPN)) return;
                InPut_BaseService14 inPut_BaseService14 = new InPut_BaseService14();
                inPut_BaseService14.BoxCode = BoxCode;
                inPut_BaseService14.NBoxCodeGrid = BoxCode2;
                inPut_BaseService14.MaterialCode = LPN;
                BoxGrid = await baseService.MergeBox(inPut_BaseService14);
                GetList_View_Box_Material();
                GetList_View_Box_Material2();
            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                LognetHelper.WriteLog("系统-Merge", ex);
            }
    
        }
        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
           
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            
        }
    }
}
